﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DevExpress.Web.ASPxClasses;
using DevExpress.Web.ASPxEditors;
using FlexySys.Common.Attributes;
using FlexySys.Common.Items;

namespace Web.Control.Item
{
    [CommonControl("CommandButton", "", "Text,CommandType,ID,Width,Height")]
    public class FlexyCommandButton : ASPxButton, ICommonCommand
    {
        public FlexyCommandButton()
        {
            CommandType = CommandType.Save;

            base.Theme = ThemesConfigurationSection.Get().Theme;
            base.ApplyTheme(ThemesConfigurationSection.Get().Theme);
        }


        public CommandType CommandType { get; set; }



        protected override void OnInit(EventArgs e)
        {

            base.OnInit(e);
        }

        protected override void OnLoad(EventArgs e)
        {
            this.Click += OnButtonClick;
            base.OnLoad(e);
        }

        private void OnButtonClick(object sender, EventArgs e)
        {
            if (ExecuteCommand != null)
                ExecuteCommand(this, new CommonCommandEventArgs(CommandType));
        }

        protected override void OnUnload(EventArgs e)
        {
            base.OnUnload(e);
            this.Click -= OnButtonClick;
        }

        public event CommonCommandEventHandler ExecuteCommand;

        //public void OnExecuteCommand(CommonCommandEventArgs args)
        //{
        //    CommonCommandEventHandler handler = ExecuteCommand;
        //    if (handler != null) handler(this, args);
        //}
    }
}